<style>
div.user_info{flex-direction: column;align-items: flex-start}
div.user_info img{height: 1.7em;}
</style>
<template>
  <list_url ref="list_url" :config="config">
    <template #user_info="{row}">
      <div class="user_info flex">
        <p class="flex"><img v-if="row.head_img" :src="row.head_img" alt="">{{row.nickname}}</p>
        <p>电话：{{row.phone}}</p>
      </div>
    </template>
    <template #action="{row}">
      <el-button v-if="row.status==1" @click="show_verify(row)" size="small">审核</el-button>
    </template>
  </list_url>

  <el-dialog v-model="dialog_verify.show" title="审核" width="600px" style="max-height: 90vh;margin: 5vh auto;" :draggable="true" @closed="dialog_verify.show=false">
    <forms :remove_name="1" :config="dialog_verify.config" :btns="dialog_verify.btns"></forms>
  </el-dialog>

</template>
<script>
import {iframe, in_right_admin} from "@/js/tool.js";
import {ajax} from "@/js/api_tool.js";

export default {
  components: {},
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');
    if (is_del){
      if(in_right_admin('OfflinePay/restore')) btns['恢复'] = function(){ app.$refs['list_url'].restore() }
      if(in_right_admin('OfflinePay/delete')) btns['彻底删除'] = function(){ app.$refs['list_url'].delete() }
    }else {
      if(in_right_admin('OfflinePay/add')) btns['添加'] = function(){ iframe('offline_pay/edit') }
      if(in_right_admin('OfflinePay/del')) btns['删除'] = function(){ app.$refs['list_url'].del() }
      if(in_right_admin('OfflinePay/recycle')) btns['回收站'] = function(){ iframe('offline_pay/index?is_del=1') }
    }
    let status_map = '全部|,待提交|0,待审核|1,支付成功|2,支付失败|3';
    let pay_type_map = '全部|,余额|yue,微信|wechat,微信服务商|wechat_partner,线下支付|offline';
    let forms_config = {
      create_time: {label:'下单时间',name:'where[create_time][between]',config:'Y-M-D',type:'date_between',value:'',add_radio:true},
      status: {label:'状态',name:'where[status][eq]',config:status_map,type:'radio',button:1,value:''},
      phone: {label:'用户电话',name:'where[user.phone][eq]',type:'text_one',value:''},
      pay_no: {label:'支付单号',name:'where[pay_no][like]',type:'text_one',value:''},
    };
    let list_cols = {
      id: {name:'id', label:'ID', width:'65px', fixed:'left', order:false},
      pay_no: {name:'pay_no', label:'支付单号', type:'text_more', width:'100px'},
      user_info: {name:'user_info', label:'支付用户', width:'140px', type:'user_info'},
      // head_img: {name:'head_img', label:'头像', width:'45px', type:'file_img'},
      // nickname: {name:'nickname', label:'昵称', width:'120px', type:''},
      // phone: {name:'phone', label:'电话', width:'120px', type:''},
      pay_img: {name:'pay_img', label:'收款码', width:'60px', type:'file_img'},
      pay_money: {name:'pay_money', label:'支付金额', width:'80px', type:''},
      pay_verify_file: {name:'pay_verify_file', label:'支付凭证', width:'60px', type:'file_imgs'},
      note_user: {label:'用户备注',name:'note_user',type:'text_more', min_width:'120px'},
      note_admin: {label:'审核备注',name:'note_admin',type:'text_more', min_width:'120px'},
      status: {name:'status', label:'状态', width:'80px', type:'select_one', config:status_map},
      verify_time: {name:'verify_time', label:'审核时间', width:'165px', type:''},
    };
    if (is_del){
      list_cols['delete_time'] = {name:'delete_time', label:'删除时间', width:'165px', type:'datetime'};
    }else {
      list_cols['create_time'] = {name:'create_time', label:'下单时间', width:'165px'};
    }
    list_cols['action'] = {name:'action', label:'操作', width:'65px', type:'action', fixed:'right'};

    return {
      config: {
        api: '/admin/offline_pay/'+(is_del?'recycle':'list'),
        title: "支付记录列表"+(is_del?'(已删除)':''),
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          return list;
        },
        limit: 20,
        p: this.$get('p', 1),
      },

      dialog_verify: {
        show: false,
        config: {
          pay_money: {label:'支付金额',name:'pay_money',type:'text_one',value:'', is_info:true},
          pay_verify_file: {label:'支付凭证',name:'pay_verify_file',type:'file_imgs',value:'', is_info:true},
          note_user: {label:'用户备注',name:'note_user',type:'text_more',value:'', is_info:true},
          note_admin: {label:'审核备注',name:'note_admin',type:'text_more',value:''},
        },
        btns: [
          {title:'不通过', type:'danger', onclick(){app.edit_verify({status:3})}},
          {title:'通过', type:'primary', onclick(){app.edit_verify({status:2})}},
        ],
        list_row: {},
      },
    }
  },
  methods: {
    edit_verify(data){
      let id = this.dialog_verify.list_row.id;
      let url = `/admin/offline_pay/edit?id=`+id;
      ajax({url:url, method:'POST', data:data, loading:true}, (res)=>{
        this.$refs.list_url.list();
        this.dialog_verify.show = false;
      })
    },
    show_verify(row){
      this.dialog_verify.list_row = row;
      this.dialog_verify.config.pay_money.value = row.pay_money;
      this.dialog_verify.config.pay_verify_file.value = row.pay_verify_file;
      this.dialog_verify.config.note_user.value = row.note_user;
      this.dialog_verify.show = true;
    },
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;

  }
}
</script>
